package net.hn.hnms.biz.examination.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.examination.domain.dto.BaseIdRespDTO;
import net.hn.hnms.biz.examination.domain.dto.BaseIdsReqDTO;
import net.hn.hnms.biz.examination.domain.dto.PagingReqDTO;
import net.hn.hnms.biz.examination.domain.dto.UserBookDTO;
import net.hn.hnms.biz.examination.service.UserBookService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 错题本控制器
 * </p>
 */
@Api(tags = {"错题本"})
@RestController
@RequestMapping("/exam/api/user/wrong-book")
public class UserBookController extends BaseController {

    @Autowired
    private UserBookService baseService;


    /**
     * 批量删除
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public R<Void> delete(@RequestBody BaseIdsReqDTO reqDTO) {
        //根据ID删除
        baseService.removeByIds(reqDTO.getIds());
        return R.ok();
    }

    /**
     * 分页查找
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @RequestMapping(value = "/paging", method = {RequestMethod.POST})
    public R<IPage<UserBookDTO>> paging(@RequestBody PagingReqDTO<UserBookDTO> reqDTO) {
        //分页查询并转换
        IPage<UserBookDTO> page = baseService.paging(reqDTO);
        return R.ok(page);
    }

    /**
     * 查找列表，每次最多返回200条数据
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "查找列表")
    @RequestMapping(value = "/next", method = {RequestMethod.POST})
    public R<BaseIdRespDTO> nextQu(@RequestBody UserBookDTO reqDTO) {
        //转换并返回
        String quId = baseService.findNext(reqDTO.getExamId(), reqDTO.getQuId());
        return R.ok(new BaseIdRespDTO(quId));
    }
}
